package com.pixelengine.Task26Oee;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.pixelengine.HBasePeHelperCppConnector;
import com.pixelengine.PeTiler;
import com.pixelengine.TileComputeResult;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.cache.CacheProperties;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

@SpringBootApplication
public class Task26OeeApplication {

    public static void main(String[] args) {
        System.out.println("Open Earth Engine 2024/4/6");
        System.out.println("version v1.0.0.0");

        //1.update pom.xml for jar 2024/4/8
        //2.update scriptwmts-template.xml remove useless variables for Qgis3.30+ 2024/4/8
        System.out.println("version v1.0.1.0 update pom.xml scriptwmts-template.xml");

        //1.add sdui
        //2.add output rawdata 2024/4/9
        System.out.println("version v1.1.0.0 sdui, outraw");

        //1.add rois
        //2.add getRoi3 2024/4/10
        System.out.println("version v1.2.1.0 rois, getRoi3");

        //1.comment out buffer dictionary.
        System.out.println("version v1.3.0.0 no buff dict");
        //1.fixed sdui.
        System.out.println("version v1.3.1.0 fixed sdui");
        //1.getRoi3 support wkt, add geomById(...); no change in java codes.
        System.out.println("version v1.3.2.1 getRoi3 support wkt, add geomById(...)");

        //1.add get tiles from COG
        System.out.println("version v1.4.0.0 get tiles from COG");
        //1.add workbench apis
        System.out.println("version v1.5.0.0 workbench apis");
        //1.add styles
        System.out.println("version v1.6.0.0 styles");
        //1.logs
        System.out.println("version v1.7.0.0 logs");
        System.out.println("version v1.7.0.1 some debug info, nothing important.");//2024/9/6
        //1. add nodata for productinfo
        System.out.println("version v1.8.0.0 add nodata for productinfo");//2024/9/24

        // 使用格式化字符串拼接COG文件路径。2025/4/28
        // System.out.println("version v1.9.0.0 cog file path format string");
        // fix getStyleData for styleid without extension of .json
        // fix can not find placeholder.png
        System.out.println("version v1.9.1.0 fix some bugs");

        // 2025/6/7
        // fix: check filenameTemplate is null in productinfo.
        // feature: add demo index.html in src/main/resources/static
        System.out.println("version v1.9.2.0 fix some bugs and add demo page inside.");

        //2025/6/27
        // feature: add {EXTRA} variable string for cog tiff filepath.
        System.out.println("version v1.9.3.1 {EXTRA} str for filepath.");
        System.out.println("version v1.9.4.2 add sdui in demo html.");// 2025/7/1

        //2025/7/8
        // (1) feature add PeTiler.GetTileDataFromCog2 support resample alg.
        // (2) modify product json add resampleAlg params.
        // (3) hide debug infos.
        //System.out.println("version v1.10.0.0 resampleAlg, hide debuginfo");// 2025/7/8
        // (4) add simple cache for tile png.
        // (5) add style.html
        System.out.println("version v1.10.0.2 cache");// 2025/7/8
        //invalidate style and productinfo
        System.out.println("version v1.11.0.0 invalidate style and productinfos");// 2025/7/11


        System.out.println("usage: java -jar Task26Oee.jar config.json");
        if( args.length<1 ) {
            System.out.println("args is empty");
            System.exit(11) ;
        }
        String configjsonfilename = args[0] ;
        System.out.println("config json filename : " + configjsonfilename);
        boolean configok = TheConfig.init(configjsonfilename) ;
        if( configok==false ) {
            System.out.println("parse config failed.");
            System.exit(12) ;
        }

        //Test libPeTiler OK?
        PeTiler tiler = new PeTiler();
        System.out.println("libPeTiler version "+ tiler.version());

        HBasePeHelperCppConnector cc = new HBasePeHelperCppConnector();
        System.out.println("PixelEngine Versions: " + cc.GetVersion() );
        TileComputeResult res1 = cc.RunScriptForTileWithRenderWithExtra(
                "com/pixelengine/TileFilePixelEngineHelper",
                "function main(){ return null;}",
                "",
                "",
                0,
                0,
                0
        ) ;

        //test
        ByteBuffer bb = ByteBuffer.allocate(8);
        bb.order(ByteOrder.BIG_ENDIAN);
        float v=1.0f;
        bb.putFloat(v);
        bb.putFloat(v);
        byte[] tempbarr = bb.array();



        SpringApplication.run(Task26OeeApplication.class, args);
    }

}
